﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ECare.BUS.Data;

namespace ECare.Client.controls
{
    public partial class ucResoucesInfo : UserControl
    {
        public ucResoucesInfo()
        {
            InitializeComponent();
        }

        public ResoucesInfo CurrentResource { get; set; }

        public int Order
        {
            get { return (int)this.lblOrder.Value; }
            set { this.lblOrder.Value=value; }
        }
        public string ResourceCode { get; set; }
        public int ResourceId { get; set; }
        public decimal Number { get; set; }

        public int CarNumber { get; set; }
        public bool IsChangeCar { get; set; }

        public void LoadInformation()
        {
            this.lblOrder.Text = this.Order.ToString();
            this.lblResouceCode.Text = this.ResourceCode+"_"+this.CurrentResource.ResourceName;
            this.txtNumber.Value =(decimal) this.Number;

            this.txtCarNumber.Value = this.CarNumber;
            this.cbChangeCar.Checked = this.IsChangeCar;

        }

        public void SetOrder(int index)
        {
            this.lblOrder.Value = index;
            this.Order = index;
        }

        public decimal GetNumber()
        {
            return this.txtNumber.Value;
        }

        public int GetCarNumber()
        {
            return (int)this.txtCarNumber.Value ;
        }

        public bool GetIsChangeCar()
        {
            return this.cbChangeCar.Checked;
        }



        public event ResourceRemovedHandler Removed;
        public event ResourceRemovedHandler UpCompelted;
        public event ResourceRemovedHandler DownCompleted;


        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要 删除这个物料?", "信息提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                return;

            if (this.Removed != null)
            {
                this.Removed(this.CurrentResource,this);
            }

        }

        private void btnUp_Click(object sender, EventArgs e)
        {
            if (this.UpCompelted != null)
            {
                this.UpCompelted(this.CurrentResource,this);
            }
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            if (this.DownCompleted != null)
            {
                this.DownCompleted(this.CurrentResource, this);
            }
        }


        public bool ValidateNumber()
        {
            if (this.txtNumber.Value == 0)
            {
                this.errorProvider1.SetError(this.txtNumber, "?");
                return false;
            }
            else
            {
                this.errorProvider1.SetError(this.txtNumber, "");
                return true;
            }
        }

    }

    public delegate void ResourceRemovedHandler(ResoucesInfo resource,ucResoucesInfo control);

   
}
